<?php
# file that contain functions to work work with current page

# function will return id of current page
function c_get_page(){
	$page_id = I_MAIN_PAGE;
	# if logged in - go to home page
	if( isset($_SESSION['user_id']) ) $page_id = I_HOME_PAGE;
	if( isset($_GET['id']) ){
		$page_id = $_GET['id'];
		if ( !isset($_SESSION['user_id']) // allow user to see other pages only if he is authorised in system
			&& ($page_id != I_MAIN_PAGE && $page_id != I_REGISTRATION_PAGE) ){
			
			$page_id = I_MAIN_PAGE;
		}
	}
	
	return $page_id;
}

# this function will escape all special symbols in given string
function c_escape($string){
	$esc_string = mysql_real_escape_string($string);
	
	return $esc_string;
} // c_escape

# function that will save the error message
# paramenters:
# * $msg - string with error message
function i_set_msg_err($msg){
	$_SESSION['msg_err'][] = $msg;
} // i_set_msg_err()

# function that will save the information message
# paramenters:
# * $msg - string with information message
function i_set_msg_inf($msg){
	$_SESSION['msg_inf'][] = $msg;
} // i_set_msg_inf()

# function that will return array of error messages
function i_get_msg_err(){
	$msg = $_SESSION['msg_err'];
	$_SESSION['msg_err'] = array(); // clear array with messages
	return $msg;
} // i_get_msg_err()

# function that will return array of information messages
function i_get_msg_inf(){
	$msg = $_SESSION['msg_inf'];
	$_SESSION['msg_inf'] = array(); // clear array with messages
	return $msg;
} // i_get_msg_inf()

# function that will return true is there are errors in array or false if array is empty.
function has_errors(){
	$res = !empty($_SESSION['msg_err']);
	return $res;
} // has_errors()

# function that will return true is there are messages in array or false if array is empty.
function has_inf_msg(){
	$res = !empty($_SESSION['msg_inf']);
	return $res;
} // has_errors()
?>